

package com.thxrinfo.stop.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.pig.common.core.util.R;
import com.pig4cloud.pig.common.log.annotation.SysLog;
import com.thxrinfo.stop.api.entity.RegionLot;
import com.thxrinfo.stop.service.RegionLotService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 
 *
 * @author ct
 * @date 2023-02-01 11:12:20
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/regionlot" )
@Tag(name = "停车位管理")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class RegionLotController {

    private final  RegionLotService regionLotService;


    /**
     * 分页查询
     * @param page 分页对象
     * @param regionLot 
     * @return
     */
    @Operation(summary = "分页查询", description = "分页查询")
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('stop_regionlot_get')" )
    public R getRegionLotPage(Page page, RegionLot regionLot) {
        return R.ok(regionLotService.getPage(page, regionLot));
    }


    /**
     * 通过id查询
     * @param id id
     * @return R
     */
    @Operation(summary = "通过id查询", description = "通过id查询")
    @GetMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('stop_regionlot_get')" )
    public R getById(@PathVariable("id" ) Long id) {
        return R.ok(regionLotService.getOneById(id));
    }

    /**
     * 新增
     * @param regionLot 
     * @return R
     */
    @Operation(summary = "新增停车位管理", description = "新增停车位管理")
    @SysLog("新增" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('stop_regionlot_add')" )
    public R save(@RequestBody @Validated RegionLot regionLot) {
		return R.ok(regionLotService.save(regionLot));
    }

    /**
     * 修改
     * @param regionLot 
     * @return R
     */
    @Operation(summary = "修改停车位管理", description = "修改停车位管理")
    @SysLog("修改" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('stop_regionlot_edit')" )
    public R updateById(@RequestBody RegionLot regionLot) {
        return R.ok(regionLotService.updateById(regionLot));
    }

    /**
     * 通过id删除
     * @param id id
     * @return R
     */
    @Operation(summary = "通过id删除停车位管理", description = "通过id删除停车位管理")
    @SysLog("通过id删除" )
    @DeleteMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('stop_regionlot_del')" )
    public R removeById(@PathVariable Long id) {
        return R.ok(regionLotService.removeById(id));
    }

}
